home *** CD-ROM | disk | FTP | other *** search
- Path: oxy.rust.net!usenet
- From: ebennett@rust.net
- Newsgroups: comp.lang.c++
- Subject: Re: Visual C++ 4.0 lacking initializers?
- Date: Thu, 25 Jan 1996 04:01:19 GMT
- Organization: Rust Net - High Speed Internet in Detroit 810-642-2276
- Message-ID: <4e6koa$ela@oxy.rust.net>
- References: <31049C46.A26@oz.is>
- NNTP-Posting-Host: liv-18.rust.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hßlfdan Ingvarsson <halfdan@oz.is> wrote:
-
- >Is it me or is this sort of code not possible with VC++ 4.0?
-
- >// Declarations of class Foo
-
- >// VC++ Complains about the line below with the error
- >// error C2436: '__ctor' : cannot initialize member functions
- >Foo::Foo(void) : Foo::Foo(10) {}
-
- >Foo::Foo(x)
- >{
- > // Some stuff
- >}
-
- I'm not 100% positive, but I do not believe this is possible with any
- C++ compiler. I do not think that a class constructor can call
- another constructor of the same class.
-
- I'm also not sure if a constructor with a void parameter is legal.
-
- The solution is to create an init method like so:
-
- Foo::Init (x)
- {
- // do some stuff
- };
-
- Foo::Foo()
- {
- Init(10);
- };
-
- Foo::Foo(x)
- {
- Init(x);
- };
-
- Don't forget type specifiers for the x's in the parameter
- declarations, by the way.
-
- Earl Bennett
-
-
-